from google.appengine.ext import webapp
from DataClass.WebsiteRec import WebsiteRec
from google.appengine.api import users
from google.appengine.ext.webapp import template
from AdminBase import AdminBase
from DataClass.FileData import FileData

import os
import cgi 

class EditFilesHandler(AdminBase):
    def GetTemplateFileName(self):
        return 'Pages/editfiles.html'
        
    def GetBreadcrumbList(self):
        return [['main', 'admin'],['files', 'editfiles']]
    
    def GetTemplateValuesDict(self, template_values, user):
        retval = template_values

        querystring=cgi.FieldStorage()
        try:
            offset=int(querystring.getvalue('offset'))
        except:
            offset = 0
        try:
            amount=int(querystring.getvalue('amount'))
        except:
            amount = 20
        
        Website = template_values['currentwebsite']
        Files = FileData.GetFilesForSiteNameWithAmountAndOffset(Website.sitename, amount, offset)

        template_values['files'] = Files
        template_values['amount'] = amount
        template_values['neednext'] = len(Files) == amount
        template_values['needprev'] = offset = 0
        template_values['nextoffset'] = offset + amount
        template_values['prevoffset'] = offset - amount
                    
        return retval
